package com.topfinance.frame.util;

import java.io.*;

import com.topfinance.frame.exception.AppException;

public class FileUtil {

	public static String readFile(String fname) throws AppException {
		String input = null;
		File file = new File(fname);
		if (!file.exists()) {
			//System.out.println("对不起文件不存在!");
			throw new AppException("[文件不存在]'" + fname + "'");
		}
		
		StringBuffer result = new StringBuffer();// 结果字符串
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));// 得到流对象
			String tempString = null;
			int line = 1;
			// 组装字符串
			while ((tempString = reader.readLine()) != null) {
				result = result.append(tempString);
				line++;
			}
			input = result.toString();// 存入返回结果数组
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					// 关闭流对象
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return input;
	}

}
